package com.atls.eduservice.controller.front;

import com.atls.commonutils.R;
import com.atls.eduservice.entity.EduCourse;
import com.atls.eduservice.entity.EduTeacher;
import com.atls.eduservice.service.EduCourseService;
import com.atls.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //查询8条热门课程，4条热门讲师
    @GetMapping("index")
    public R index() {
        //查询热门课程
        /*QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapper);



        //查询热门讲师
        QueryWrapper<EduTeacher> teacherWrapper=new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);*/

        //查询热门课程
        List<EduCourse> courseList=courseService.selectHostCourse();
        //查询热门讲师
        List<EduTeacher> teacherList=teacherService.selectHostTeacher();

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);

    }
}
